package ar.com.ironsoft.javaopenauth.web;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ar.com.ironsoft.javaopenauth.oauth.OAuthService;
import ar.com.ironsoft.javaopenauth.utils.Constants;

@SuppressWarnings("serial")
public class OAuthCallbackServlet extends HttpVisibleServlet {

	public OAuthCallbackServlet(OAuthService service) {
		super(service);
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws IOException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws IOException {
		getService().executeCallbackAction(request.getQueryString());
		setOAuthToken(request,getService().getToken());
		
		//Return control to application
		response.sendRedirect(getService().getCallbackAppURL());
	}

}
